package com.movitech.mobile.cz.base.purchase.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.movitech.mobile.cz.base.purchase.entity.WFlowFormExtSubMng;
import com.movitech.mobile.cz.base.purchase.mapper.WFlowFormExtSubMngMapper;
import com.movitech.mobile.cz.base.purchase.service.WFlowFormExtSubMngService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 流程表单-外网-招标管理-子表 服务实现类
 * </p>
 *
 * @author Movitech Mobile
 * @since 2018-04-26
 */
@Service
public class WFlowFormExtSubMngServiceImpl extends ServiceImpl<WFlowFormExtSubMngMapper, WFlowFormExtSubMng> implements WFlowFormExtSubMngService {

    @Override
    public List<WFlowFormExtSubMng> getByParentId(String parentId) {
        return selectList(new EntityWrapper<WFlowFormExtSubMng>().eq("flow_form_ext_mng_id",parentId).orderBy("segments_number"));
    }

    @Override
    public WFlowFormExtSubMng selectByParentIdAndSn(String parentId, Integer sn) {

        return selectOne(new EntityWrapper<WFlowFormExtSubMng>().eq("flow_form_ext_mng_id",parentId).eq("segments_number",sn));
    }

    @Override
    public WFlowFormExtSubMng updateByParentIdAndSn(Integer actionStatus,String parent, Integer sn) {
        WFlowFormExtSubMng where = new WFlowFormExtSubMng();
        where.setFlowFormExtMngId(parent);
        where.setSegmentsNumber(sn);
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.setEntity(where);
        WFlowFormExtSubMng wFlowFormExtSubMng = selectOne(entityWrapper);

        wFlowFormExtSubMng.setActionStatus(actionStatus);
        updateById(wFlowFormExtSubMng);
        return wFlowFormExtSubMng;
    }

    @Override
    public void updateByEntity(Integer actionStatus, WFlowFormExtSubMng where) {
        WFlowFormExtSubMng wFlowFormExtSubMng = new WFlowFormExtSubMng();
        wFlowFormExtSubMng.setActionStatus(actionStatus);
        EntityWrapper entityWrapper = new EntityWrapper();
        entityWrapper.setEntity(where);
        update(wFlowFormExtSubMng,entityWrapper);
    }
}
